#! /usr/bin/python

v = -2 * 10**11
n = 5000
s = 0
r, delta_r = 1, 0.1
while abs(s - v) > 1:
    s = sum((300 - k) * r**(k-1) for k in range(1, n+1))
    r = (r + delta_r) if s > v else (r - delta_r)
    delta_r /= 2
 
print 'Answer to PE235 = %.12f' % r


increment = 0.001
r = 1.0
while(1):
     r += increment
     s = sum((300 - k) * r**(k-1) for k in range(1, 5001))
     print s, r
     if s > -6*10**12: r -= 0.000001

print r
